<template>
  <div class="container">
    <div class="title">
      <span>添加</span>
      <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
    </div>
    <el-divider></el-divider>
    <el-form label-width="90px">
      <div class="wrap">
        <el-form-item label="会员卡名称" prop="name">
          <el-input
                  size="medium"
                  v-model="name"
                  placeholder="请填写会员卡名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="会员卡类型" prop="type">
          <el-select v-model="type" clearable filterable placeholder="请选择会员卡类型">
            <el-option
                    v-for="item in typeData"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="会员卡金额" prop="money">
          <el-input
                  size="medium"
                  type="number"
                  v-model="money"
                  placeholder="请填写会员卡金额"
          ></el-input>
        </el-form-item>
        <el-form-item label="每周查看联系方式次数" prop="look_num">
          <el-input
              size="medium"
              type="number"
              v-model="look_num"
              placeholder="每周查看联系方式次数"
          ></el-input>
        </el-form-item>
        <el-form-item class="submit">
          <el-button type="primary" @click="createValue()">保 存</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import MemberType from '@/models/member-type'

export default {
  data() {
    return {
      typeData: [{
        id: 1,
        name: '日卡',
      },
      {
        id: 2,
        name: '周卡',
      },
      {
        id: 3,
        name: '月卡',
      },
      {
        id: 4,
        name: '季卡',
      },
      {
        id: 5,
        name: '年卡',
      }],
      name: '',
      money: '',
      type: '',
      look_num: '',
    }
  },
  mounted() {},
  methods: {
    back() {
      this.$emit('addClose')
    },
    async createValue() {
      const info = {
        name: this.name,
        type: this.type,
        money: this.money,
        look_num: this.look_num,
      }
      const res = await MemberType.createData(info)
      if (res.error_code === 0) {
        this.$message.success(`${res.msg}`)
        this.back()
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.el-divider--horizontal {
  margin: 0;
}

.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;

    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
